<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Happy dong
 * Created Time: 2019-09-17 13:58
 *
 * Version: 2.0
 */

namespace App\Modules\Store\Controllers;


use Flower\Core\Repository\Eloquent\BaseService;
use Illuminate\Support\Facades\Log;
use Yansongda\Pay\Pay;

class WxPayController extends BaseService
{

	protected $config;
	public function __construct()
	{
		$this->config = config('wx.pay');
	}

	public function index()
	{
		$order = [
			'out_trade_no' => time(),
			'total_fee' => '1', // **单位：分**
			'body' => 'test body - 测试',
			'openid' => 'onkVf1FjWS5SBIixxxxxxx',
		];

		$pay = Pay::wechat($this->config)->mp($order);

		// $pay->appId
		// $pay->timeStamp
		// $pay->nonceStr
		// $pay->package
		// $pay->signType
	}

	public function notify()
	{
		$pay = Pay::wechat($this->config);

		try{
			$data = $pay->verify(); // 是的，验签就这么简单！

			Log::debug('Wechat notify', $data->all());
		} catch (\Exception $e) {
			// $e->getMessage();
		}

		return $pay->success();// laravel 框架中请直接 `return $pay->success()`
	}
}